const browserSync = require('browser-sync').create();
const chokidar = require("chokidar");
const { createProxyMiddleware } = require('http-proxy-middleware');

/**
 * 反向代理中间件
 * 参考：https://github.com/chimurai/http-proxy-middleware
*/
const middleware = [
  // createProxyMiddleware(['/api'], {
  //   target: '',
  //   changeOrigin: true,
  //   ws: true,
  //   pathRewrite: {
  //     '^/api': ''
  //   },
  //   headers: {}
  // })
]

browserSync.init({
  server: {
    files: '**',
    baseDir: './src/',
    directory: true,
    middleware: middleware
  },
  port: 80,
  // notify: false
});

chokidar.watch('./src').on('all', (event, path) => {
  // console.log(event, path);
  browserSync.reload();
});